//
//  IDDCacheManagerProtocol.h
//  ComJia
//
//  Created by Aslan on 17/02/2017.
//  Copyright © 2017 ComJia. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "IDDFoundation.h"

typedef NS_ENUM (NSInteger, IDDCacheEntityType) {
    IDDCacheEntityTypePrivate,
    IDDCacheEntityTypePublic,
};

@interface IDDCacheEntity : NSObject

@property (nonatomic, strong) id cache;
@property (nonatomic, strong) NSString *key;
@property (nonatomic, strong) NSString *path;
@property (nonatomic, assign) IDDCacheEntityType type;
@property (nonatomic, assign) BOOL dirty;
@property (nonatomic, strong) NSDate *date;
@property (nonatomic, assign) unsigned long long size;

- (instancetype)initWithCache:(id)cache forKey:(NSString *)key atPath:(NSString *)path andType:(IDDCacheEntityType)type;

@end

typedef void (^IDDCacheManagerCallback)(IDDCacheEntity *, IDDError *);


@protocol IDDCacheManagerProtocol <NSObject>

// set these two properties to initialize data store
@property (nonatomic, copy) NSString *privateCacheDirectory;
@property (nonatomic, copy) NSString *publicCacheDirectory;

#pragma mark size

- (unsigned long long)cacheSize;

// path can be nil
- (unsigned long long)privateCacheSizeAtPath:(NSString *)path;

- (unsigned long long)publicCacheSizeAtPath:(NSString *)path;

#pragma mark clean
- (void)cleanCache;

// path can be nil
- (void)cleanPrivateCacheAtPath:(NSString *)path;

- (void)cleanPublicCacheAtPath:(NSString *)path;

#pragma mark cache

- (IDDCacheEntity *)privateCacheForKey:(NSString *)key error:(IDDError **)error;

- (IDDCacheEntity *)privateCacheForKey:(NSString *)key atPath:(NSString *)path error:(IDDError **)error;

- (void)privateCacheForKey:(NSString *)key finished:(IDDCacheManagerCallback)finished;

- (void)privateCacheForKey:(NSString *)key atPath:(NSString *)path finished:(IDDCacheManagerCallback)finished;

- (IDDCacheEntity *)setPrivateCache:(id)cache forKey:(NSString *)key error:(IDDError **)error;

- (IDDCacheEntity *)setPrivateCache:(id)cache forKey:(NSString *)key atPath:(NSString *)path error:(IDDError **)error;

- (IDDCacheEntity *)publicCacheForKey:(NSString *)key error:(IDDError **)error;

- (IDDCacheEntity *)publicCacheForKey:(NSString *)key atPath:(NSString *)path error:(IDDError **)error;

- (void)publicCacheForKey:(NSString *)key finished:(IDDCacheManagerCallback)finished;

- (void)publicCacheForKey:(NSString *)key atPath:(NSString *)path finished:(IDDCacheManagerCallback)finished;

- (IDDCacheEntity *)setPublicCache:(id)cache forKey:(NSString *)key error:(IDDError **)error;

- (IDDCacheEntity *)setPublicCache:(id)cache forKey:(NSString *)key atPath:(NSString *)path error:(IDDError **)error;

- (IDDCacheEntity *)setEntity:(IDDCacheEntity *)entity error:(IDDError **)error;

@end
